package com.sky.service.impl;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.context.BaseContext;
import com.sky.dto.*;
import com.sky.entity.*;
import com.sky.exception.AddressBookBusinessException;
import com.sky.exception.OrderBusinessException;
import com.sky.mapper.*;
import com.sky.result.PageResult;
import com.sky.service.OrderService;
import com.sky.utils.DateUtil;
import com.sky.utils.WeChatPayUtil;
import com.sky.vo.*;
import com.sky.websocket.WebSocketServer;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author normal
 * @date 2025年02月28日 下午11:21
 */
@Service
@Slf4j
@AllArgsConstructor
public class OrderServiceImpl implements OrderService {

    private DishMapper dishMapper;
    private AddressBookMapper addressBookMapper;
    private OrderMapper orderMapper;
    private ShoppingCartMapper shoppingCartMapper;
    private OrderDetailMapper orderDetailMapper;
    private WebSocketServer webSocketServer;


    /**
     * 微信支付工具类
     */
    private WeChatPayUtil weChatPayUtil;

    /**
     * 用户业务映像
     */
    private UserMapper userMapper;

    /**
     * 订单提交
     *
     * @param dto
     * @return
     */
    public OrderSubmitVO submitOrder(OrdersSubmitDTO dto) {
        Long userId = BaseContext.getCurrentId();

        // 处理业务异常 (收货地址薄为空、购物车数据为空)
        verifyOrderParam(dto,userId);

        // 构建订单数据
        Orders buidOrders = buildOrders(dto, userId);

        // 向订单表插入一条数据
        orderMapper.insert(buidOrders);

        // 向订单明细表插入多条购物车相关数据（使用批量插入）
        List<OrderDetail> list = new ArrayList<>();
        shoppingCartMapper.selectByUserId(userId).forEach(
                (shoppingCart) -> {
                    OrderDetail orderDetail = new OrderDetail();
                    BeanUtils.copyProperties(shoppingCart, orderDetail);
                    orderDetail.setOrderId(buidOrders.getId());
                    list.add(orderDetail);
                }
        );
        orderDetailMapper.insertBatch(list);

        // 清空购物车
        shoppingCartMapper.deleteByUserId(userId);

        OrderSubmitVO vo =OrderSubmitVO.builder()
                .id(userId)
                .orderAmount(buidOrders.getAmount())
                .orderTime(buidOrders.getOrderTime())
                .orderNumber(buidOrders.getNumber())
                .build();
        return vo;
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO 订单相关属性
     * @return
     * @throws Exception
     */
    public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        Long userId = BaseContext.getCurrentId();
        User user = userMapper.selectById(userId);
        // 调用微信支付接口，生成预支付交易单
        JSONObject jsonObject = weChatPayUtil.pay(
                ordersPaymentDTO.getOrderNumber(),
                new BigDecimal(0.01),
                "苍穹外卖订单(normal)",
                user.getOpenid()
        );
        if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("ORDERPAID")) {
            throw new OrderBusinessException("订单已支付");
        }

        OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
        vo.setPackageStr(jsonObject.getString("package"));

        return vo;
    }

    /**
     * 支付成功，修改订单状态
     * @param number
     */
    public void paySuccess(String number) {
        // 根据订单号查询订单
        Orders ordersDB = orderMapper.getByNumber(number);

        log.info("当前订单信息为:{}", ordersDB);

        // 更具订单id更新订单的状态
        Orders orders = Orders.builder()
                .id(ordersDB.getId())
                .status(Orders.TO_BE_CONFIRMED)
                .payStatus(Orders.PAID)
                .checkoutTime(LocalDateTime.now())
                .build();
        orderMapper.update(orders);

        // 通过websocket向客户端发送消息
        Map map = new HashMap();
        // 1来单提醒 2客户催单
        map.put("type",1);
        map.put("orderId",ordersDB.getId());
        map.put("content","订单号:" + ordersDB.getNumber());
        String json = JSON.toJSONString(map);
        webSocketServer.sendMessageToAll(json);
    }

    /**
     * 订单根据订单状态查询分页数据
     *
     * @param ordersPageQueryDTO page(页码) pageSize(分页大小) status(订单状态)
     * @return
     */
    public PageResult pageQueryOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        // 开启分页插件
        PageHelper.startPage(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());
        Long userId = BaseContext.getCurrentId();
        ordersPageQueryDTO.setUserId(userId);
        Page<Orders> orders = orderMapper.pageQuery(ordersPageQueryDTO);

        // 查询菜单详情并与订单基本信息合并
        List<OrderVO> result = orders.stream().map(order -> {
            List<OrderDetail> orderDetail = orderDetailMapper.selectByOrderId(order.getId());
            OrderVO orderVO = new OrderVO();
            BeanUtils.copyProperties(order, orderVO);
            orderVO.setOrderDetailList(orderDetail);
            return orderVO;
        }).collect(Collectors.toList());


        PageResult pageResult = new PageResult();
        pageResult.setTotal(orders.getTotal());
        pageResult.setRecords(result);


        return pageResult;
    }

    /**
     * 取消订单
     * @param id 订单id
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void cancelOrders(Long id) {
        // 根据id查询订单
        Orders ordersDB = orderMapper.selectById(id);

        // 处理订单不存在
        if (ordersDB == null) {
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 7退款
        // 仅允许状态<=2,才能进行取消订单
        if (ordersDB.getStatus() > Orders.TO_BE_CONFIRMED) {
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }

        Orders orders = new Orders();
        // 订单状态处于待付款，需要进行退款操作
        if (ordersDB.getStatus().equals(Orders.TO_BE_CONFIRMED)) {
            // 微信退款操作
            // todo: 未对接微信接口不能实现直接跳过；

            // 修改订单状态为退款状态
            orders.setPayStatus(Orders.REFUND);
        }

        // 更新订单状态、取消原因、取消时间
        orders.setId(id);
        orders.setStatus(Orders.CANCELLED);
        orders.setCancelReason("用户取消");
        orders.setCancelTime(LocalDateTime.now());
        orderMapper.update(orders);
    }

    /**
     * 管理端取消订单
     *
     * @param ordersCancelDTO
     */
    @Override
    public void cancelOrders(OrdersCancelDTO ordersCancelDTO) {
        // 校验参数
        if (ordersCancelDTO == null) {
            log.error("参数异常");
            throw new IllegalArgumentException("参数异常");
        }

        // 1. 查询订单是否存在
        Orders orders = orderMapper.selectById(ordersCancelDTO.getId());
        if (orders == null) {
            log.error("订单:{}不存在", ordersCancelDTO.getId());
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 2. 订单状态 >= 待接单 进行退款操作
        if (orders.getStatus() >= Orders.TO_BE_CONFIRMED) {
            // todo: 微信未对接暂时不需要退款

            // 设置订单支付状态为退款
            orders.setPayStatus(Orders.REFUND);
        }

        // 3. 修改订单状态退款、取消原因、取消时间
        orders.setStatus(Orders.CANCELLED);
        orders.setCancelReason(ordersCancelDTO.getCancelReason());
        orders.setCancelTime(LocalDateTime.now());
        orderMapper.update(orders);

    }

    /**
     * 根据订单ID获取完整订单信息(包含订单明细)
     * @param id 订单id
     * @return 组装完成的订单视图对象，包含主订单和订单明细
     */
    public OrderVO getOrderWithDetail(Long id) {
        // 获取主订单数据
        Orders orders = orderMapper.selectById(id);
        if (orders == null) {
            log.error("订单不存在，orderId:{}", id);
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 获取关联订单明细
        List<OrderDetail> orderDetail = orderDetailMapper.selectByOrderId(orders.getId());

        // 组装视图对象
        OrderVO orderVO = new OrderVO();
        BeanUtils.copyProperties(orders, orderVO);
        orderVO.setOrderDetailList(orderDetail);
        log.info("订单id[{}]查询成功, 包含{}个明细项",orderVO.getId(),orderVO.getOrderDetailList().size());
        return orderVO;
    }

    /**
     * 将原订单中的商品重新加入到购物车中
     * @param id 订单ID
     */
    @Override
    public void repetitionOrder(Long id) {
        Long userId = BaseContext.getCurrentId();
        log.info("再来一单，用户ID[{}]",id);
        // 1. 订单数据校验
        Optional.ofNullable(orderMapper.selectById(id))
                .orElseThrow(() -> {
                    log.error("订单[{}]不存在,请求用户ID:{}", id, BaseContext.getCurrentId());
                    return new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
                });

        // 2. 获取原订单明细
        List<OrderDetail> originOrderDetail = orderDetailMapper.selectByOrderId(id);

        // 注意： 当originOderDetail为空时，静默跳过不处理
        if (originOrderDetail != null && originOrderDetail.size() > 0 ) {
            // 3. 订单明细数据转换
            List<ShoppingCart> shoppingCarts = new ArrayList<>();
            originOrderDetail.forEach(detail -> {
                // 将订单明细表的各项数据进行转换为购物车对象
                ShoppingCart shoppingCart = new ShoppingCart();
                BeanUtils.copyProperties(detail, shoppingCart);
                shoppingCart.setId(null);
                shoppingCart.setUserId(userId);
                shoppingCarts.add(shoppingCart);
            });
            // 4. 批量插入购物车商品
            Integer insertCount = shoppingCartMapper.insertBatch(shoppingCarts);
            log.info("用户[{}]再来一单执行成功,插入购物车{}数据项", userId, insertCount);
        }


    }

    /**
     * 条件分页查询订单信息
     * @param ordersPageQueryDTO
     * @return
     */
    @Override
    public PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        // 校验参数
        if (ordersPageQueryDTO == null){
            log.error("参数异常");
            throw new OrderBusinessException("参数异常");
        }

        // 1. 开启分页插件
        PageHelper.startPage(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());

        // 2. 开始查询订单
        Page<OrderVO> page = orderMapper.selectCondition(ordersPageQueryDTO);

        // 3. 将订单菜品拼接为字符串,并添加到OrderVO对象
        for (OrderVO ordervo : page) {
            // 根据订单号查询菜品
            List<OrderDetail> orderDetails = orderDetailMapper.selectByOrderId(ordervo.getId());
            // 拼接菜单 比如 宫保鸡丁*3
            String orderDishes = orderDetails.stream().map(item ->item.getName() + "*" + item.getNumber()).collect(Collectors.joining(","));
            ordervo.setOrderDishes(orderDishes);
        }

        // 4. 封装分页对象
        PageResult pageResult = new PageResult();
        pageResult.setTotal(page.size());
        pageResult.setRecords(page.getResult());
        return pageResult;
    }

    /**
     * 统计订单状态数量  2待接单 3已接单 4派送中
     *
     *
     * @return
     */
    @Override
    public OrderStatisticsVO countOrdersStatus() {
        OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
        ordersPageQueryDTO.setStatus(Orders.TO_BE_CONFIRMED);

        // 1. 待接单计数
        Integer toBeConfirmed = orderMapper.selectCondition(ordersPageQueryDTO).size();
        // 2. 已接单
        ordersPageQueryDTO.setStatus(Orders.CONFIRMED);
        Integer confirmed = orderMapper.selectCondition(ordersPageQueryDTO).size();
        // 3. 派送中
        ordersPageQueryDTO.setStatus(Orders.DELIVERY_IN_PROGRESS);
        Integer deliveryInProgress = orderMapper.selectCondition(ordersPageQueryDTO).size();

        // 4. 构建订单状态计数对象
        OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();
        orderStatisticsVO.setConfirmed(confirmed);
        orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);
        orderStatisticsVO.setToBeConfirmed(toBeConfirmed);

        log.info("订单状态计数: 带派送数量{}, 派送中数量{}, 待接单数量{}",deliveryInProgress, confirmed, toBeConfirmed);

        return orderStatisticsVO;
    }

    /**
     * 管理端进行接单
     * @param ordersConfirmDTO
     */
    @Override
    @Transactional
    public void confirmedOrder(OrdersConfirmDTO ordersConfirmDTO) {
        // 1. 判断订单数据是否存在
        Orders orders = orderMapper.selectById(ordersConfirmDTO.getId());
        if (orders == null) {
            log.error("接单业务:订单不存在");
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 2. 检验订单状态
        if (orders.getStatus() > Orders.TO_BE_CONFIRMED) {
            log.error(MessageConstant.ORDER_STATUS_ERROR);
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }

        // 3. 修改订单状态为接单状态
        orders.setStatus(Orders.CONFIRMED);
        orderMapper.update(orders);
    }

    /**
     * 管理端拒单 根据订单id
     * @param rejectionDTO
     */
    @Override
    public void rejectOrders(OrdersRejectionDTO rejectionDTO) {
        // 1. 判断订单数据是否存在
        Orders orders = orderMapper.selectById(rejectionDTO.getId());
        if (orders == null) {
            log.error("拒单业务:订单不存在");
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 2. 检验订单状态 > 2(待付款)
        if (orders.getStatus() > Orders.TO_BE_CONFIRMED) {
            log.error("该订单已不可拒单");
            throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
        }

        // 3. 判断订单是否付款
        if (orders.getStatus().equals(Orders.TO_BE_CONFIRMED)) {
            // todo 进行微信退款

            orders.setPayStatus(Orders.REFUND);
        }


        LocalDateTime now = LocalDateTime.now();
        // 修改订单取消状态、拒单原因、取消原因
        orders.setStatus(Orders.CANCELLED);
        orders.setCancelReason("商家拒单");
        orders.setRejectionReason(rejectionDTO.getRejectionReason());
        orders.setCancelTime(now);
        orderMapper.update(orders);
    }

    /**
     * 派送订单,将订单id设置为派送中
     * @param id
     */
    @Override
    public void deliveryOrders(Long id) {
        // 1. 判断订单数据是否存在
        Orders orders = orderMapper.selectById(id);
        if (orders == null) {
            log.error("派送订单业务:订单不存在");
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 2. todo： 校验？


        // 3. 修改订单状态为派送中
        orders.setStatus(Orders.DELIVERY_IN_PROGRESS);
        // TODO: 派送时间有问题
        orders.setDeliveryTime(LocalDateTime.now());
        orderMapper.update(orders);
    }

    /**
     * 完成订单
     *
     * @param id 订单id
     */
    @Override
    public void completeOrders(Long id) {
        // 1. 判断订单数据是否存在
        Orders orders = orderMapper.selectById(id);
        if (orders == null) {
            log.error("完成订单业务:订单不存在");
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 2. 修改订单为完成
        orders.setStatus(Orders.COMPLETED);
        orderMapper.update(orders);
    }

    /**
     * 用户催单
     *
     * @param id
     */
    @Override
    public void reminder(Long id) {
        log.info("用户催单:{}", id);
        Orders orders = orderMapper.selectById(id);
        if (orders == null) {
            log.error("用户催单业务:订单不存在");
            throw new OrderBusinessException(MessageConstant.ORDER_NOT_FOUND);
        }

        // 通过websocket向客户端发送消息
        Map msgMap = new HashMap();
        msgMap.put("type", 1);
        msgMap.put("orderId", orders.getId());
        msgMap.put("content","订单号:" + orders.getNumber());
        String json = JSON.toJSONString(msgMap);
        webSocketServer.sendMessageToAll(json);
    }


    /**
     * 订单数量统计 (开始时间 ~ 结束时间)期间的订单统计
     *
     * @param reportDTO 开始时间 - 结束时间
     * @return
     */
    @Override
    public OrderReportVO getOrderStatistics(ReportDTO reportDTO) {
        log.info("获取订单统计数据:{}", reportDTO);
        // 开始时间到结束时间的日期时间 2024-2-1 ~ 2024-2-5
        List<LocalDate> dateList = DateUtil.getBetweenDates(reportDTO.getBegin(), reportDTO.getEnd());
        // 订单总数数量集合
        List<Integer> orderCountList = new ArrayList<>();
        // 订单有效数量集合
        List<Integer> validOrderCountList = new ArrayList<>();

        dateList.forEach(date -> {
            // 当天的最开始时间 00:00:00
            LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
            // 当天的最后时间 23:59:59
            LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
            // 查询当天订单总数
            Integer orderCount = orderMapper.countOrdersStatus(beginTime, endTime, null);
            if (orderCount == null) {
                orderCount = 0;
            }

            // 查询当天有效订单总数
            Integer validOrderCount = orderMapper.countOrdersStatus(beginTime, endTime, Orders.COMPLETED);
            if (validOrderCount == null) {
                validOrderCount = 0;
            }
            orderCountList.add(orderCount);
            validOrderCountList.add(validOrderCount);
        });
        // 总订单数量集合 拼接为(,)隔开的字符串
        String orderCountListStr = ArrayUtil.join(orderCountList.toArray(new Integer[0]), ",");
        // 有效订单集合 拼接为(,)隔开的字符串
        String validOrderListStr = ArrayUtil.join(validOrderCountList.toArray(new Integer[0]), ",");
        // 日期集合 拼接为(,)隔开的字符串
        String dateListStr = ArrayUtil.join(dateList.toArray(new LocalDate[0]), ",");
        // 完成率 有效总数订单 / 总订单数
        Integer totalValidOrderCount = validOrderCountList.stream().reduce(0, Integer::sum);
        Integer totalOrderCount = orderCountList.stream().reduce(0, Integer::sum);

        double orderCompletionRate;
         if (totalOrderCount == 0) {
             orderCompletionRate = 0.0;
         }else {
             orderCompletionRate = (totalValidOrderCount * 1.0 / totalOrderCount);
         }



        return OrderReportVO.builder()
                .dateList(dateListStr)
                .orderCountList(orderCountListStr)
                .validOrderCountList(validOrderListStr)
                .totalOrderCount(totalOrderCount)
                .validOrderCount(totalValidOrderCount)
                .orderCompletionRate(orderCompletionRate)
                .build();
    }

    /**
     * 获取营业额统计
     * @param reportDTO
     * @return
     */
    @Override
    public TurnoverReportVO getTurnoverStatistics(ReportDTO reportDTO) {
        // 需要查询日期集合
        List<LocalDate> dateList = DateUtil.getBetweenDates(reportDTO.getBegin(), reportDTO.getEnd());
        // 营业额集合
        List<BigDecimal> turnoverList = new ArrayList<>();
        dateList.forEach(date -> {
            LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
            BigDecimal amount = orderMapper.getTurnoverByDate(beginTime, endTime);
            turnoverList.add(amount);
        });
        return TurnoverReportVO.builder()
                .turnoverList(ArrayUtil.join(turnoverList.toArray(new BigDecimal[0]), ","))
                .dateList(ArrayUtil.join(dateList.toArray(new LocalDate[0]), ","))
                .build();
    }

    @Override
    public UserReportVO getUserStatistics(ReportDTO reportDTO) {

        // 日期列表
        List<LocalDate> dateList = DateUtil.getBetweenDates(reportDTO.getBegin(), reportDTO.getEnd());
        List<Integer> newUserList = new ArrayList<>();
        List<Integer> totalUserList = new ArrayList<>();
        dateList.forEach(date -> {
            LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
            // 当天新增用户数量
            Integer newUser = userMapper.countByCreateTime(beginTime, endTime);
            newUserList.add(newUser);
            // 查询总用户数量
            Integer totalUser = userMapper.countByCreateTime(null, endTime);
            totalUserList.add(totalUser);

        });
        return UserReportVO.builder()
                .dateList(ArrayUtil.join(dateList.toArray(new LocalDate[0]), ","))
                .newUserList(ArrayUtil.join(newUserList.toArray(new Integer[0]), ","))
                .totalUserList(ArrayUtil.join(totalUserList.toArray(new Integer[0]),","))
                .build();
    }

    /**
     * 获得销量TOP10
     * @param reportDTO
     * @return
     */
    @Override
    public SalesTop10ReportVO getSalesTop10(ReportDTO reportDTO) {
        List<GoodsSalesDTO> top10 = orderMapper.getSalesTop10(reportDTO);


        return SalesTop10ReportVO.builder()
                .nameList(ArrayUtil.join(top10.stream().map(GoodsSalesDTO::getName).toArray(), ","))
                .numberList(ArrayUtil.join(top10.stream().map(GoodsSalesDTO::getNumber).toArray(), ","))
                .build();
    }

    /**
     * 构建订单对象
     * @param dto
     * @param userId
     * @return
     */
    private Orders buildOrders(OrdersSubmitDTO dto, Long userId) {
        // 获取用户地址簿信息
        AddressBook addressBook = addressBookMapper.getById(dto.getAddressBookId());
        Orders buidOrders = new Orders();
        BeanUtils.copyProperties(dto, buidOrders);
        buidOrders.setUserId(userId);
        buidOrders.setStatus(Orders.PAID);
        buidOrders.setOrderTime(LocalDateTime.now());
        buidOrders.setPayStatus(Orders.PENDING_PAYMENT);
        buidOrders.setPhone(addressBook.getPhone());
        buidOrders.setConsignee(addressBook.getConsignee());
        // 返回一个时间戳 作为订单号
        buidOrders.setNumber(String.valueOf(System.currentTimeMillis()));
        buidOrders.setAddress(addressBook.getDetail());
        buidOrders.setUserName(addressBook.getProvinceName());
        return buidOrders;
    }


    /**
     * 处理业务异常
     *
     * @param dto
     * @param userId
     */
    private void verifyOrderParam(OrdersSubmitDTO dto, Long userId) {

        AddressBook addressBook = addressBookMapper.getById(dto.getAddressBookId());
        // 处理收货地址为空
        if (addressBook == null) {
            throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
        }

        // 处理购物车数据为空
        List<ShoppingCart> shoppingCarts = shoppingCartMapper.selectByUserId(userId);
        if (shoppingCarts.isEmpty()) {
            throw new AddressBookBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
        }

    }





}
